package com.uam.core.entity.model.entity.response;

import com.uam.core.lk.utils.ResponseResult;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import static com.uam.core.lk.utils.ResponseResult.SUCCESS;

/**
 * @Description 请求结果封装
 * @Author heguanglong
 * @Date 2019-02-19 10:54
 **/
@Data
@ApiModel("通用的数据返回对象")
public class CommonResult<T> {

    @ApiModelProperty("返回状态：1失败，0成功")
    private Integer status;
    @ApiModelProperty("返回提示信息")

    private String message;
    @ApiModelProperty("返回的数据对象")

    private T result;

    public CommonResult() {
        this.setStatus(SUCCESS);
        this.setMessage("success");
    }

    public CommonResult(T data) {
        this.setStatus(SUCCESS);
        this.setMessage("success");
        this.setResult(data);
    }


    public CommonResult(ResponseResult result) {
        this.setStatus(result.getCode());
        this.setMessage("success");
        this.setResult((T)result.getData());
    }




    /**
     * 调用返回自定义的信息，无数据返回前端
     * @param <T>
     * @date 2019/10/10 17:37
     * @modify heguanglong
     */
    public static <T> CommonResult<T> build(int status, String msg) {
        CommonResult rs = new CommonResult<>();
        rs.setStatus(status);
        rs.setMessage(msg);
        return rs;
    }
}
